package com.example.team.service.Imp;

import com.example.team.dao.IAttendanceDao;
import com.example.team.entity.Attendance;
import com.example.team.service.IAttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/****
 * 编写者：王轩
 * 时间：2023/10/27
 * 打卡信息
 */
@Service
@Transactional
public class IAttendanceServiceImpl implements IAttendanceService {
    @Autowired
    private IAttendanceDao attendanceDao;

    //下班打卡
    //如果打卡时id不存在返回-1
    @Override
    public int updateTime(Attendance attendance) {
        List<Attendance> list = attendanceDao.findByEmployeeID(attendance);
        if (list.size()>0){
            return attendanceDao.updateTime(attendance);
        }else {
            return -1;
        }
    }

    @Override
    public List<Attendance> findByEmployeeID(Attendance attendance) {
        return attendanceDao.findByEmployeeID(attendance);
    }

    //添加上班打卡
    //如果打卡时id以存在返回-1
    @Override
    public int insertAttendance(Attendance attendance) {
        List<Attendance>attendanceList=new ArrayList<>();
        attendanceList=attendanceDao.findByEmployeeID(attendance);
        if(attendanceList.size()>0){
            return -1;
        }else {
            return attendanceDao.insertAttendance(attendance);
        }
    }
    //删除打卡信息
    //如果id不存在返回-1
    @Override
    public int deleteAttendance(Attendance attendance) {
        List<Attendance>attendances=attendanceDao.findByEmployeeID(attendance);
        if(attendances.size()<=0){
            return -1;
        }else if (attendance.getAttendanceID()==null){
            return -1;
        }else {
            return attendanceDao.deleteAttendance(attendance);
        }
    }
    //更改打卡信息
    @Override
    public int update(Attendance attendance) {
        return attendanceDao.update(attendance);
    }
    //查询所有打卡信息
    @Override
    public List<Attendance> getAllAttendance(Attendance attendance) {
        return attendanceDao.getAllAttendance(attendance);
    }
    //单条件查询
    @Override
    public Attendance getAttendance(Attendance attendance) {
        return attendanceDao.getAttendance(attendance);
    }
}
